package knowse.app.daos;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;

public class CommitDAO {
	// If error message is needed
	private final String TAG = "CommitDAO";
	private final String ERRORMSG = "Insertion failed";
	// Table name
	protected static final String Table = "Commit";
	// Primary key
	protected static final String CommitID = "CommitID";
	// Other attributes
	protected static final String json_class = "json_class";
	protected static final String AuthorName = "AutorName";
	protected static final String StartTime = "StartTime";
	protected static final String StartDate = "StartDate";
	protected static final String CommitHash = "CommitHash";
	protected static final String ShortCommitHash = "ShortCommitHash";
	// Foreign key
	protected static final String LogID = "LogID";
	
	public CommitDAO() {
		
	}
	
	public void store(CommitDataObject cdo, Integer logID) throws Exception{
	
		ContentValues values= new ContentValues();
		values.put(json_class, cdo.getJsonClass());
		values.put(AuthorName, cdo.getAuthorName());
		values.put(StartTime, cdo.getStartTime());
		values.put(StartDate, cdo.getStartDate());
		values.put(CommitHash, cdo.getCommitHash());
		values.put(ShortCommitHash, cdo.getShortCommitHash());
		
		values.put(LogID, logID);
		
		DBHelper dbHelper = new DBHelper();
		
		SQLiteDatabase db = dbHelper.getWritableDatabase();
		
		long insertResult = db.insert(Table, null, values);
		if(insertResult < 0){
			throw new Exception(TAG + " " + ERRORMSG);
		}
		db.close();
		
	}
	
}
